﻿using System;
using System.IO;

namespace HigLabo.Net.WindowsLive
{
    /// <summary>
    /// 
    /// </summary>
    public class UploadFileCommand : WindowsLiveCommand
    {
        private Byte[] _FileData = null;
        /// <summary>
        /// 
        /// </summary>
        public override HttpMethodName MethodName
        {
            get
            {
                return HttpMethodName.Put;
            }
        }
#if !SILVERLIGHT && !NETFX_CORE
        /// <summary>
        /// 
        /// </summary>
        /// <param name="apiPath">フォーマット: FOLDER_ID/files </param>
        /// <param name="filePath">ローカルファイルのフルパス</param>
        public UploadFileCommand(String apiPath, String filePath)
            : this(apiPath, filePath, true)
        {

        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="apiPath">フォーマット: FOLDER_ID/files </param>
        /// <param name="filePath">ローカルファイルのフルパス</param>
        /// <param name="newName">新た名前 (拡張子の指定必要)</param>
        public UploadFileCommand(String apiPath, String filePath, String newName)
            : this(apiPath, filePath, true, newName)
        {

        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="apiPath">フォーマット: FOLDER_ID/files </param>
        /// <param name="filePath">ローカルファイルのフルパス</param>
        /// <param name="overwrite">true:切り換えできる. false:切り換えできません.</param>
        public UploadFileCommand(String apiPath, String filePath, Boolean overwrite)
            : this(apiPath, filePath, overwrite, Path.GetFileName(filePath))
        {

        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="apiPath">フォーマット: FOLDER_ID/files </param>
        /// <param name="filePath">ローカルファイルのフルパス</param>
        /// <param name="overwrite">true:切り換えできる. false:切り換えできません.</param>
        /// <param name="newName">新た名前 (拡張子の指定必要)</param>
        public UploadFileCommand(String apiPath, String filePath, Boolean overwrite, String newName)
            : base(apiPath)
        {
            this.GraphApiPath += "/files/" + newName;
            this._FileData = System.IO.File.ReadAllBytes(filePath);
            if (!overwrite)
            {
                //the default value is true
                this.UrlParameter = "&overwrite=false";
            }
            this.ContentType = "";
        }
#endif
        /// <summary>
        /// 
        /// </summary>
        /// <param name="apiPath"></param>
        /// <param name="fileData"></param>
        /// <param name="overwrite"></param>
        /// <param name="newName"></param>
        public UploadFileCommand(String apiPath, Byte[] fileData, Boolean overwrite, String newName)
            : base(apiPath)
        {
            this.GraphApiPath += "/files/" + newName;
            this._FileData = fileData;
            if (!overwrite)
            {
                //the default value is true
                this.UrlParameter = "&overwrite=false";
            }
            this.ContentType = "";
        }
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        protected override byte[] SetData()
        {
            return _FileData;
        }
    }
}
